package com.tanhua.api.impl.mongo;

import com.tanhua.api.mongo.TanHuaApi;
import com.tanhua.domain.mongo.RecommendUser;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;
@Service
public class TanHuaApiImpl implements TanHuaApi {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<RecommendUser> findCard(Long userId) {

        Query query = new Query(Criteria.where("toUserId").is(userId));
        query.with(new Sort(Sort.Direction.DESC,"score"));
        List<RecommendUser> recommendQuanziList = mongoTemplate.find(query, RecommendUser.class);
        return  recommendQuanziList;
    }

    @Override
    public void tanhuaUnlove(Long uid, Long userId) {
        Query query = new Query(Criteria.where("userId").is(uid).and("toUserId").is(userId));

        mongoTemplate.remove(query,RecommendUser.class);
    }
}